<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Taikhoan_model extends CI_Model {


	var $matk = '';
	var $tentaikhoan = '';
	var $matkhau = '';
	var $hoten = '';
	var $diachi = '';
	var $sodienthoai = '';
	var $email = '';
	var $trangthai = '';
	var $quyen = '';	
	
    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
		$this->load->database();
    }
	 
	function insert($data)
    {
		if($data['trangthai'] == "Không hoạt động") $data['trangthai'] = 0;
		if($data['quyen'] == "Quản trị") $data['quyen'] = 1;
        $this->db->insert('taikhoan', $data);
    }
	
	function getresult_index()
	{
		$this->db->select("matk,tentaikhoan,matkhau,hoten,diachi,sodienthoai,email,trangthai,quyen");
	    $query=$this->db->get("taikhoan");
        return $query->result_array();
	}
	
	function update($data, $matk)
    {
		$this->db->where("matk", $matk);
      	return $this->db->update('taikhoan', $data);
    }
	
	function gettaikhoan($matk)
	{
		$this->db->select("matk,tentaikhoan,matkhau,hoten,diachi,sodienthoai,email,trangthai,quyen");
		$this->db->where("matk", $matk);
        $query = $this->db->get("taikhoan");
       	return $query->row_array();
	}
	
	function delete($matk)
    {
        $this->db->delete('taikhoan', "`matk` = '".$matk."'");
    }
}
?>